/**
 * Copyright 2009-2010 - YangJiandong(chunquedong)
 * 
 * This file is part of ChunMap project
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
 * 你可以自由复制、传播本项目的下载包文件，但必须保持其完整性。
 * 我们不用对使用中的风险及由此造成的损失承担任何责任。
 * 详细情况请见《ChunMap许可协议》。

 * 想了解更多有关ChunMap的信息，请访问http://code.google.com/p/chunmap/
 */
package chunmap.view.layer;

import java.util.ArrayList;
import java.util.List;

import chunmap.model.elem.Envelope;
import chunmap.model.elem.EnvelopeBuilder;
import chunmap.view.Renderer;
/**
 * 图层集合
 * @author chunquedong
 * 
 */
public class LayerCollection {
	private Layer decorateLayer;// 装饰层
	private Layer selectedLayer;// 选择层
	private List<Layer> layers = new ArrayList<Layer>();
	private Envelope envelop;

	public void add(Layer layer) {
		layers.add(layer);
		reComputeEnvelop();
	}

	public void render(Renderer r) {
		for (Layer lyr : layers) {
			lyr.render(r);
		}
		if (selectedLayer != null)
			selectedLayer.render(r);
		if (decorateLayer != null)
			decorateLayer.render(r);
	}

	public Envelope getEnvelop() {
		return envelop;
	}

	public void reComputeEnvelop() {
		EnvelopeBuilder env = new EnvelopeBuilder();
		for (Layer lyr : layers) {
			env.mergeEnvelop(lyr.getEnvelop());
		}
		envelop = env.toEnvelop();
	}

	public Layer getDecorateLayer() {
		return decorateLayer;
	}

	public void setDecorateLayer(Layer decorateLayer) {
		this.decorateLayer = decorateLayer;
	}

	public Layer getSelectedLayer() {
		return selectedLayer;
	}

	public void setSelectedLayer(Layer selectedLayer) {
		this.selectedLayer = selectedLayer;
	}

	public List<Layer> getLayers() {
		return layers;
	}

	public void setLayers(List<Layer> layers) {
		this.layers = layers;
		reComputeEnvelop();
	}
}
